/**
 *  vector2.cpp
 *  AwkwardPaint - Engine
 *
 *  Date: 11/08/2013
 *
 *  Language: C++
 *
 *  @author Carl McCaffrey
 *
 */
#include "math/vector2.h"

#include <math.h>

Vector2::Vector2(void)
{
    x = 0;
    y = 0;
}

Vector2::Vector2(float xPos, float yPos)
{
    x = xPos;
    y = yPos;
}

float Vector2::Magnitude(void)
{
    return sqrt(pow(x, 2) + pow(y, 2));
}

void Vector2::Normalize(void)
{
    float mag = Magnitude();
    x /= mag;
    y /= mag;
}

float Vector2::Dot(Vector2 vec1, Vector2 vec2)
{
    return ((vec1.x * vec2.x) + (vec1.y * vec2.y));
}

void Vector2::Project(Vector2 axis, Vector2 vertex[], float &min, float &max)
{
    float dot_prod = Dot(vertex[0], axis);
    max = min = dot_prod;
    for(int i = 0; i < 4; i++){
        dot_prod = Dot(vertex[i], axis);
        if(dot_prod < min){
            min = dot_prod;
        }else
            if(dot_prod > max){
                max = dot_prod;
            }
    }
}

bool Vector2::operator==(Vector2 vec)
{
    return (x == vec.x && y == vec.y);
}

bool Vector2::operator!=(Vector2 vec)
{
    return (x != vec.x || y != vec.y);
}

Vector2 Vector2::operator=(Vector2 vec)
{
    x = vec.x;
    y = vec.y;
    return *this;
}

Vector2 Vector2::operator-(void)
{
	return Vector2(-x, -y);
}

Vector2 Vector2::operator-(Vector2 vec)
{
	return Vector2(x - vec.x, y - vec.y);
}

Vector2 Vector2::operator+(Vector2 vec)
{
	return Vector2(x + vec.x, y + vec.y);
}

Vector2 Vector2::operator*(float f)
{
	return Vector2(x * f, y * f);
}

Vector2 Vector2::operator/(float f)
{
	return Vector2(x / f, y / f);
}

Vector2 Vector2::operator+=(Vector2 vec)
{
	x += vec.x;
    y += vec.y;
    return *this;
}

Vector2 Vector2::operator-=(Vector2 vec)
{
	x -= vec.x;
    y -= vec.y;
    return *this;
}

Vector2 Vector2::operator*=(float f)
{
	x *= f;
    y *= f;
    return *this;
}

Vector2 Vector2::operator/=(float f)
{
	x /= f;
    y /= f;
    return *this;
}
